package top.hmtools.makedata.random;

import java.util.Date;
import java.util.Random;

public class RandomDatetime implements IRandom<Date>{

	@Override
	public Date getRandom() {
		return this.getRandom(new Date());
	}
	
	/**
	 * 获取随机日期
	 * @param max 截止日期
	 * @return
	 */
	public Date getRandom(Date max){
		if(max == null){
			return max;
		}
		
		Long randomLong = this.getRandom(0, max.getTime());
		return new Date(randomLong);
	}

	/**
	 * 获取指定范围的随机长整型数
	 * @param min
	 * @param max
	 * @return
	 */
	public Long getRandom(long min,long max){
		long offset = max - min;
		if(offset<=0){
			return 0L;
		}
		Random random = new Random();
		long temp = Math.abs(random.nextLong());
		return temp%offset+min;
	}
}
